package com.netease.financial.base.share.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.netease.financial.R;
import com.netease.financial.base.share.adapter.SharePanelAdapter;
import com.netease.financial.base.share.action.BaseShareAction;
import com.netease.financial.base.share.action.CopyLinkAction;
import com.netease.financial.base.share.action.OpenInBrowserAction;
import com.netease.financial.base.share.action.SendToEasyChatFriendAction;
import com.netease.financial.base.share.action.SendToWeChatFriendAction;
import com.netease.financial.base.share.action.SendViaSmsAction;
import com.netease.financial.base.share.model.ShareHolder;
import com.netease.financial.base.share.action.ShareOnEasyChatMomentAction;
import com.netease.financial.base.share.action.ShareOnSinaWeiboAction;
import com.netease.financial.base.share.action.ShareOnWeChatMomentAction;
import com.netease.financial.base.web.JSBridge;
import com.netease.financial.ui.dialog.BottomDialog;

/**
 * Created by wyf on 6/24/15.
 */
public class SharePanelDialog extends BottomDialog implements AdapterView.OnItemClickListener {
    private static final BaseShareAction[] SHARE_ACTIONS = {
            new SendToWeChatFriendAction(),
            new ShareOnWeChatMomentAction(),
            new SendToEasyChatFriendAction(),
            new ShareOnEasyChatMomentAction(),
            new OpenInBrowserAction(),
            new CopyLinkAction(),
            new SendViaSmsAction(),
            new ShareOnSinaWeiboAction()
    };

    private Context mContext;
//    private String mTitle;
//    private String mDescription;
//    private String mUrl;
    private SharePanelAdapter mAdapter;
    private ShareHolder mShareHolder;
    private JSBridge.Command mCommand;

    public SharePanelDialog(Context context) {
        super(context);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    private void initView() {
        View rootView = LayoutInflater.from(mContext).inflate(R.layout.dialog_share_panel, null);
        GridView sharePanel = (GridView) rootView.findViewById(R.id.sharePanel);
        mAdapter = new SharePanelAdapter(mContext, SHARE_ACTIONS);
        sharePanel.setAdapter(mAdapter);
        sharePanel.setOnItemClickListener(this);
        setContentView(rootView);
    }

    public void setShareInfo(ShareHolder holder) {
        mShareHolder = holder;
    }

    public void setCommand(JSBridge.Command command) {
        mCommand = command;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        dismiss();
        BaseShareAction shareAction = mAdapter.getItem(position);
        shareAction.setCommand(mCommand);
        shareAction.share(mContext, mShareHolder);
    }
}
